<?php
use \phiction\tester as t;
use \phiction\string_utils as str;

return [
    'indent' => function () {
        $prefix = str::INDENT_PREFIX;
        $orig = "\nhello\nworld\n\nfoo\n";
        $expect = "$prefix\n${prefix}hello\n${prefix}world\n${prefix}\n${prefix}foo\n$prefix";
        $result = str::indent($orig);
        t::must_equal($result, $expect);
    },

    'indent-by' => function () {
        $prefix = "# ";
        $orig = "\nhello\nworld\n\nfoo\n";
        $expect = "$prefix\n${prefix}hello\n${prefix}world\n${prefix}\n${prefix}foo\n$prefix";
        $result = str::indent_by($orig, $prefix);
        t::must_equal($result, $expect);
    },

    'map-line' => function () {
        $length = function (string $str): string { return strlen($str); };
        $orig = "\nhello\nworld\n\nfoo\n";
        $expect = "0\n5\n5\n0\n3\n0";
        $result = str::map_line($length, $orig);
        t::must_equal($result, $expect);
    },

    'single-lined' => function () {
        t::assert(str::single_lined("hello"), "\"hello\" is only one line");
    },

    'multi-lined' => function () {
        t::assert(str::multi_lined("hello\n"), "\"hello\\n\" has two lines");
    },
];

